package com.skivingcloud.report.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.skivingcloud.report.entity.ReportDashboardWidget;
import com.skivingcloud.report.mapper.ReportDashboardWidgetMapper;
import com.skivingcloud.report.service.ReportDashboardWidgetService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.skivingcloud.common.utils.PageParameter;

/**
 * 组件 服务层实现。
 *
 * @author skivingcloud
 * @since 2024-09-12
 */
@Service
public class ReportDashboardWidgetServiceImpl extends ServiceImpl<ReportDashboardWidgetMapper, ReportDashboardWidget> implements ReportDashboardWidgetService {

    /**
     * 分页查询组件
     *
     * @param parameter 查询参数
     * @return 分页查询结果
     */
    @Override
    public Page<ReportDashboardWidget> queryByPage(PageParameter<ReportDashboardWidget> parameter){
        Page<ReportDashboardWidget> page = new Page<>(parameter.getPage(), parameter.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (parameter.getParam() != null) {
            //查询条件
            if (StringUtils.isNoneBlank(parameter.getParam().getId())) {
                queryWrapper.and(ReportDashboardWidget::getId).like(parameter.getParam().getId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportCode())) {
                queryWrapper.and(ReportDashboardWidget::getReportCode).like(parameter.getParam().getReportCode());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getType())) {
                queryWrapper.and(ReportDashboardWidget::getType).like(parameter.getParam().getType());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getSetup())) {
                queryWrapper.and(ReportDashboardWidget::getSetup).like(parameter.getParam().getSetup());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getData())) {
                queryWrapper.and(ReportDashboardWidget::getData).like(parameter.getParam().getData());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getCollapse())) {
                queryWrapper.and(ReportDashboardWidget::getCollapse).like(parameter.getParam().getCollapse());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getPosition())) {
                queryWrapper.and(ReportDashboardWidget::getPosition).like(parameter.getParam().getPosition());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getOptions())) {
                queryWrapper.and(ReportDashboardWidget::getOptions).like(parameter.getParam().getOptions());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getEnableFlag())) {
                queryWrapper.and(ReportDashboardWidget::getEnableFlag).like(parameter.getParam().getEnableFlag());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getDeleteFlag())) {
                queryWrapper.and(ReportDashboardWidget::getDeleteFlag).like(parameter.getParam().getDeleteFlag());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getCreateBy())) {
                queryWrapper.and(ReportDashboardWidget::getCreateBy).like(parameter.getParam().getCreateBy());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getUpdateBy())) {
                queryWrapper.and(ReportDashboardWidget::getUpdateBy).like(parameter.getParam().getUpdateBy());
            }
        }
        return this.page(page, queryWrapper);
    }
}
